package com.teach;

import java.util.Arrays;

/**
 * <pre>
 * - 构造方法与字符集转换
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-04-12 15:20
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public class Demo01 {

  public static void main(String[] args)throws Exception {
    String str1 = null;
    str1 = "";
    str1 = new String();
    String str2 = "abc";
    str1 = new String("abc");//abc
    String str3 = "abc";
    String str4 = new String("abc");
    String str5 = new String("abc").intern();
    System.out.println(str2==str1);
    System.out.println(str2==str3);
    System.out.println(str1==str4);
    System.out.println(str2==str5);
    System.out.println(str1.equals(str4));

    char[] cs = {'a','b','c'};
    System.out.println(Arrays.toString(cs));
    str1 = new String(cs);
    System.out.println(str1);

    byte[] bs = {65,66,67};
    System.out.println(Arrays.toString(bs));
    str1 = new String(bs);
    System.out.println(str1);

    bs = "中国".getBytes();
    System.out.println(Arrays.toString(bs));
    bs = "中国".getBytes("GBK");
    System.out.println(Arrays.toString(bs));

    str1 = new String(bs,"GBK");
    System.out.println(str1);

    str1 = new String(bs,"ISO-8859-1");
    System.out.println(str1);

    str1 = new String(str1.getBytes("ISO-8859-1"),"GBK");
    System.out.println(str1);



  }
}
